﻿/* $RCSFile: CurrencyPricingChooser.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.Core/UI/WebControls/CurrencyPricingChooser.cs $
 * $log$
 * Revision 19 2010/10/02 14:49:04  christian.surieux
 *   Updated ADNDynImage for PimaryFieldStringValue, added name override and changed Telerik version
 * Revision 6 2010/08/06 19:56:29  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using AddonNice.Diagnostics;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.Settings;

//using AddonNice.ECommerce;
//using AddonNice.ECommerce.Helpers;
using AddonNice.Helpers;

using AddonNice.CRMWrapper;

using Telerik.Web.UI;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.UI.WebControls
{
    /// <summary>
    /// This control contains 2 radCombos, second combo being dependant of first
    /// In First we select a currency and in second we select a pricelevel
    /// </summary>
    /// 
    [ToolboxData("<{0}:CurrencyPricingChooser runat=server></{0}:CurrencyPricingChooser>")]
    public class CurrencyPricingChooser : CompositeControl
    {
        RadComboBox BoxCurrency     =   null;
        RadComboBox BoxPricing      =   null;
        bool _LoadDefaultList       =   true;
        bool _AddEmptyItem          =   false;
        int _CurrencyIndex          =   0;


        #region Properties

        public bool LoadDefaultList
        {
            get
            {
                return _LoadDefaultList;
            }
            set
            {
                _LoadDefaultList  =   value;
            }
        }
        public bool AddEmptyItem
        {
            get
            {
                return _AddEmptyItem;
            }
            set
            {
                _AddEmptyItem  =   value;
            }
        }

        public int CurrencyIndex
        {
            get
            {
                return _CurrencyIndex;
            }
            set
            {
                _CurrencyIndex  =   value;
            }
        }


        /// <summary>
        /// get or Set selected values with format 'currencyid;pricelevelid'
        /// </summary>
        public string SelectedItem
        {
            get
            {
                if (WebControlsTraceSwitch.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser SelectedItem GET ChildControlsCreated: {0}, BoxCurrency.SelectedIndex: {1}, BoxPricing.SelectedIndex: {2}.",
                        ChildControlsCreated,(ChildControlsCreated) ? BoxCurrency.SelectedIndex:-2,(ChildControlsCreated) ? BoxPricing.SelectedIndex:-2),WebControlsTraceSwitch.Sw.Info);
                string g        =   (string)ViewState["SelectedItem"];
                // when no selected values exist, try to get it from viewstate where it as been saved by the SET
                if ( ChildControlsCreated )
                {
                    string str  =   (g == null) ? string.Empty : g;
                    if ( BoxCurrency.SelectedIndex != -1 )
                    {
                        if ( BoxPricing.SelectedIndex != -1 )
                        {
                            str  =   string.Format("{0};{1}",BoxCurrency.SelectedValue,BoxPricing.SelectedValue);
                            ViewState["SelectedItem"]   =   str;
                        }
                        else
                        {
                            str  =   string.Format("{0};",BoxCurrency.SelectedValue);
                        }
                    }
                    if (WebControlsTraceSwitch.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser SelectedItem GET value: '{0}'.",str),WebControlsTraceSwitch.Sw.Info);
                    return str;
                }
                return (g == null) ? string.Empty : g;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    if (WebControlsTraceSwitch.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser SelectedItem SET value: '{0}'.",value),WebControlsTraceSwitch.Sw.Info);
                    ViewState["SelectedItem"]       =   value;
                    if ( !ChildControlsCreated )
                        return;
                    // try to apply selection
                    string[] v                      =   value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (WebControlsTraceSwitch.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser SelectedItem SET v.Length: '{0}'.",v.Length),WebControlsTraceSwitch.Sw.Info);
                    if (v.Length > 0)
                    {
                        if ( BoxCurrency.SelectedValue != v[0] )
                        {
                            RadComboBoxItem it      =   BoxCurrency.FindItemByValue(v[0]);
                            if (it != null)
                            {
                                it.Selected         =   true;
                                LoadPriceLevels(v[0]);
                                if (v.Length == 2)
                                {
                                    it              =   BoxPricing.FindItemByValue(v[1]);
                                    if (it != null)
                                        it.Selected =   true;
                                }
                            }
                        }
                        else
                        {
                            if ( ( v.Length == 2 ) && (BoxPricing.SelectedValue != v[1] ) )
                            {
                                RadComboBoxItem it  =   BoxPricing.FindItemByValue(v[1]);
                                if (it != null)
                                    it.Selected     =   true;
                            }
                        }
                    }
                }
                else ViewState["SelectedItem"]  =   string.Empty;
            }
        }

        bool _IsDatabound  =   false;
        public bool IsDatabound
        {
            get
            {
                return _IsDatabound;
            }
        }
        
        SortedList<string,ADNDynTransactionCurrency> _CurrencyList    = null;
        public SortedList<string,ADNDynTransactionCurrency> CurrencyList    
        {
            get
            {
                if (_CurrencyList == null)
                {
                    if (LoadDefaultList)
                    {
                        Guid SelectedGuid   =   Guid.Empty;
                        _CurrencyList       =   CrmHelper.GetTransactionCurrencies0(ref SelectedGuid);
                    }
                }
                return _CurrencyList;
            }
            set
            {
                _CurrencyList   =   value;
            }
        }

        #endregion Properties

        #region JScript
        /*
<script type="text/javascript">

    function LoadComboPricing(combo, eventarqs)
    {    
        var Combo2  = $find('<%= BoxPricing.ClientID %>');
        var item    = eventarqs.get_item();
        Combo2.set_text("Loading...");
        
        if (item.get_index() > 0)
        {        
            
            Combo2.requestItems(item.get_value(), false);                                
        }
        else
        {
            Combo2.set_text(" ");
            Combo2.clearItems();
        }
    }

   
    function ItemsLoaded(combo, eventarqs)
    {
        if (combo.get_items().get_count() > 0)
        {
            combo.set_text(combo.get_items().getItem(0).get_text());
            combo.get_items().getItem(0).highlight();
        }
        combo.showDropDown();
    }
</script>
         */
        
        protected virtual string makeScript(string nm)
        {
            StringBuilder sb  =     new StringBuilder();
            sb.AppendFormat("function {0}(sender, args)\n{{",nm);
            sb.AppendFormat("var Combo2  = $find('{0}');\n",BoxPricing.ClientID);
            sb.Append("var item    = args.get_item();Combo2.set_text('Loading...');\n");
            sb.Append("if (item.get_index() >= 0){   Combo2.requestItems(item.get_value(), false);}\n");
            sb.Append("else { Combo2.set_text(' ');Combo2.clearItems();}\n");
            sb.Append("}\n");
            sb.Append("function ItemsLoaded(combo, args)\n{");
            sb.Append("if (combo.get_items().get_count() > 0)\n{");
            sb.Append("combo.set_text(combo.get_items().getItem(0).get_text());\n");
            sb.Append("combo.get_items().getItem(0).highlight();\n}\n");
            sb.Append("combo.showDropDown();\n");
            sb.Append("}\n");

            string src          =   sb.ToString();
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser makeScript script={0}.",src),WebControlsTraceSwitch.Sw.Info);
            return src;
        }

        protected virtual string makeScriptName()
        {
            return string.Format("OnClientSelectedIndexChanging_{0}", ClientID);
        }

        #endregion JScript

        public CurrencyPricingChooser()
        {
            LoadDefaultList         =   true;
            AddEmptyItem            =   false;
            CurrencyIndex           =   0;
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser Ctor Called LoadDefaultList: {0}, AddEmptyItem: {1}, CurrencyIndex: {2}.",
                    LoadDefaultList,AddEmptyItem,CurrencyIndex),WebControlsTraceSwitch.Sw.Info);
        }

        public CurrencyPricingChooser(bool loadDefaultList,bool addEmptyItem,int currencyIndex)
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser Ctor Called LoadDefaultList: {0}, addEmptyItem: {1}, CurrencyIndex: {2}.",
                    LoadDefaultList,addEmptyItem,currencyIndex),WebControlsTraceSwitch.Sw.Info);
            LoadDefaultList         =   loadDefaultList;
            AddEmptyItem            =   addEmptyItem;
            CurrencyIndex           =   currencyIndex;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser Page_Load BEG IsPostBack: {0}.",Page.IsPostBack),WebControlsTraceSwitch.Sw.Info);
            // Install ajaxsettings
            if ( Page is ADNPage && Visible)
                ((ADNPage)Page).AddAjaxSetting( BoxCurrency,BoxPricing);
            if (!Page.IsPostBack)
            {
                DataBind();
            }
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser Page_Load END IsPostBack: {0}.",Page.IsPostBack),WebControlsTraceSwitch.Sw.Info);
        }

        protected override void CreateChildControls()
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser CreateChildControls BEG.",WebControlsTraceSwitch.Sw.Info);
            Controls.Clear();
            BoxCurrency                                 =   new RadComboBox();
            BoxCurrency.ID                              =   "BoxCurrency";
            BoxCurrency.CssClass                        =   "BoxCurrency";
            BoxCurrency.Width                           =   new Unit("29%"); // Pb IE if total width 100%
            BoxCurrency.OnClientSelectedIndexChanging   =   "LoadComboPricing";

			Controls.Add(BoxCurrency);
            BoxPricing                                  =   new RadComboBox();
            BoxPricing.ID                               =   "BoxPricing";
            BoxPricing.CssClass                         =   "BoxPricing";
            BoxPricing.Width                            =   new Unit("70%");
            BoxPricing.OnClientItemsRequested           =   "ItemsLoaded";
            BoxPricing.ItemTemplate                     =   new PricingTemplate();
            BoxPricing.DataTextField                    =   CrmStr.name;
            BoxPricing.DataValueField                   =   CrmStr.pricelevelid;
            BoxPricing.EnableLoadOnDemand               =   true;
            BoxPricing.ItemsRequested                   +=  new RadComboBoxItemsRequestedEventHandler(BoxPricing_ItemsRequested);
			Controls.Add(BoxPricing);
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser CreateChildControls END.",WebControlsTraceSwitch.Sw.Info);
        }

        public override void DataBind()
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser DataBind BEG IsDatabound: {0}",IsDatabound),WebControlsTraceSwitch.Sw.Info);
            if ( IsDatabound )
                return;
            EnsureChildControls();
            base.DataBind();
            LoadCurrencies();
            _IsDatabound    =   true;
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser DataBind END IsDatabound: {0}",IsDatabound),WebControlsTraceSwitch.Sw.Info);
        }

        void LoadCurrencies()
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadCurrencies BEG CurrencyList.Count: {0}.",CurrencyList.Count),WebControlsTraceSwitch.Sw.Info);
            EnsureChildControls();
            BoxCurrency.DataSource                      =   CurrencyList.Values;
            BoxCurrency.DataTextField                   =   CrmStr.currencyname;
            BoxCurrency.DataValueField                  =   CrmStr.transactioncurrencyid;
            BoxCurrency.DataBind();
            string selStr                               =   SelectedItem;
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadCurrencies SelectedItem: {0}.",selStr),WebControlsTraceSwitch.Sw.Info);
            if ( BoxCurrency.Items.Count > 0 )
            {
                if (selStr == string.Empty)
                {
                    if ( CurrencyIndex >= BoxCurrency.Items.Count )
                        CurrencyIndex                   =   0;
                    RadComboBoxItem it                  =   BoxCurrency.Items[CurrencyIndex];
                    it.Selected                         =   true;
                    LoadPriceLevels(it.Value);
                }
                else
                {
                    string[] v                          =   selStr.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadCurrencies v.Length: {0}.",v.Length),WebControlsTraceSwitch.Sw.Info);
                    if (v.Length > 0)
                    {
                        RadComboBoxItem it              =   BoxCurrency.FindItemByValue(v[0]);
                        if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                            Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadCurrencies v[0]: {0}, it != null: {1}.",v[0],(it != null)),WebControlsTraceSwitch.Sw.Info);
                        if (it != null)
                        {
                            it.Selected                 =   true;
                            LoadPriceLevels(v[0]);
                        }
                    }
                    else
                    {
                        if ( CurrencyIndex >= BoxCurrency.Items.Count )
                            CurrencyIndex               =   0;
                        RadComboBoxItem it              =   BoxCurrency.Items[CurrencyIndex];
                        it.Selected                     =   true;
                    }
                }
            }
        }
    
        void LoadPriceLevels(string selCurrencyID)
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadPriceLevels BEG selCurrencyID: {0}.",selCurrencyID),WebControlsTraceSwitch.Sw.Info);
            EnsureChildControls();
            Guid currencyID                             =   new Guid(selCurrencyID);
            Guid SelectedGuid                           =   Guid.Empty;
            SortedList<string,ADNDynPricelevel> PricelevelList    =   CrmHelper.GetPriceListsByCurrency(currencyID,ref SelectedGuid);
            // Add the Empty item if not coming from cache
            const string EmptyItem                      =   " ";
            if ( AddEmptyItem && !PricelevelList.ContainsKey(EmptyItem) )
            {
                ADNDynPricelevel EmptPl                 =   new ADNDynPricelevel(CrmHelper.ResetWrapper, Guid.Empty);
                EmptPl.pricelevelid                     =   Guid.Empty;
                EmptPl.name                             =   "No selection";
                EmptPl.description                      =   EmptPl.name;
                EmptPl.begindate                        =   CRMUtil.minDateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture);
                EmptPl.enddate                          =   CRMUtil.maxDateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture);
                EmptPl.PropertyDescriptorCollection     =   (PricelevelList.Count > 0) ? PricelevelList.Values[0].PropertyDescriptorCollection : null;
                PricelevelList.Add(EmptyItem, EmptPl);
            }
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadPriceLevels PricelevelList.Count: {0}.",PricelevelList.Count),WebControlsTraceSwitch.Sw.Info);
            BoxPricing.DataTextField                    =   CrmStr.name;
            BoxPricing.DataValueField                   =   CrmStr.pricelevelid;
            BoxPricing.DataSource                       =   PricelevelList.Values;
            BoxPricing.DataBind();

            string selStr                               =   SelectedItem;
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser LoadPriceLevels SelectedItem: {0}.",selStr),WebControlsTraceSwitch.Sw.Info);
            if ( BoxPricing.Items.Count > 0 )
            {
                if (selStr == string.Empty)
                {
                    RadComboBoxItem it                  =   BoxPricing.Items[0];
                    it.Selected                         =   true;
                }
                else
                {
                    string[] v                          =   SelectedItem.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if ( (v.Length == 2) && ( selCurrencyID == v[0] ) )
                    {
                        RadComboBoxItem it              =   BoxPricing.FindItemByValue(v[1]);
                        if ( it != null )
                            it.Selected                 =   true;
                    }
                    else
                    {
                        RadComboBoxItem it              =   BoxPricing.Items[0];
                        it.Selected                     =   true;
                    }
                }
            }
        }

        void BoxPricing_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadPriceLevels(e.Text);
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CurrencyPricingChooser OnPreRender BEG IsPostBack: {0}", Page.IsPostBack), WebControlsTraceSwitch.Sw.Info);
            EnsureChildControls();
            string nm                                   =   makeScriptName();
            BoxCurrency.OnClientSelectedIndexChanging   =   nm;
            if ( Page is ADNPage )
                ((ADNPage)Page).RegisterADNClientScriptBlock(GetType(), nm, makeScript(nm), true);
            base.OnPreRender(e);
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine("[V]CurrencyPricingChooser OnPreRender END.", WebControlsTraceSwitch.Sw.Info);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser RenderContents BEG.",WebControlsTraceSwitch.Sw.Info);
            try
            {
                AddAttributesToRender(writer);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "CurrencyPricingChooser", false);
                writer.RenderBeginTag("div");
                BoxCurrency.RenderControl(writer);
                BoxPricing.RenderControl(writer);
                writer.RenderEndTag();
            }
            catch (Exception ex)
            {
                if ( WebControlsTraceSwitch.Sw.TraceError )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CurrencyPricingChooser RenderContents ex: {0}",ex),WebControlsTraceSwitch.Sw.Info);
                throw;
            }
             if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser RenderContents END.",WebControlsTraceSwitch.Sw.Info);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser Render BEG.",WebControlsTraceSwitch.Sw.Info);
            if ( DesignMode )
                EnsureChildControls();
            try
            {
                base.Render(writer);
            }
            catch (Exception ex)
            {
                if ( WebControlsTraceSwitch.Sw.TraceError )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CurrencyPricingChooser Render ex: {0}",ex),WebControlsTraceSwitch.Sw.Info);
                throw;
            }
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser Render END.",WebControlsTraceSwitch.Sw.Info);
        }

        /// <summary>
        ///  Template for boxPricing
        /// </summary>
        class PricingTemplate : ITemplate
        {
            public PricingTemplate()
            {

                if ( DataTypeTraceSwitch.Sw.TraceVerbose )
                    Trace2.WriteLine( "[V]PricingTemplate Ctor.",DataTypeTraceSwitch.Sw.Info);
            }

            /// <summary>
            /// Instantiate the control
            /// </summary>
            public void InstantiateIn(Control container)
            {
                if (DataTypeTraceSwitch.Sw.TraceVerbose)
                    Trace2.WriteLine("[V]PricingTemplate InstantiateIn BEG.", DataTypeTraceSwitch.Sw.Info);
                Table tab               =   new Table();
                tab.ID                  =   "tab_" + container.ClientID;
                tab.CellPadding         =   2;
                tab.CellSpacing         =   0;

                TableRow r              =   new TableRow();

                TableCell c             =   new TableCell();
                c.Width                 =   new Unit(100,UnitType.Pixel);
                Label label             =   new Label();
                label.ID                =   "LblName";
                c.Controls.Add(label);
                r.Controls.Add(c);
                    
                c                       =   new TableCell();
                c.Width                 =   new Unit(50,UnitType.Pixel);
                label                   =   new Label();
                label.ID                =   "LbBegindate";
                c.Controls.Add(label);
                r.Controls.Add(c);

                c                       =   new TableCell();
                c.Width                 =   new Unit(50,UnitType.Pixel);
                label                   =   new Label();
                label.ID                =   "LbEnddate";
                c.Controls.Add(label);
                r.Controls.Add(c);

                c                       =   new TableCell();
                c.Width                 =   new Unit(200,UnitType.Pixel);
                label                   =   new Label();
                label.ID                =   "LbDescription";
                c.Controls.Add(label);
                r.Controls.Add(c);

                tab.Controls.Add(r);
                tab.DataBinding         +=  new EventHandler(tab_DataBinding);
                container.Controls.Add(tab);
                if (DataTypeTraceSwitch.Sw.TraceVerbose)
                    Trace2.WriteLine("[V]PricingTemplate InstantiateIn END.", DataTypeTraceSwitch.Sw.Info);
            }

            private void tab_DataBinding(object sender, EventArgs e)
            {
                if ( DataTypeTraceSwitch.Sw.TraceVerbose )
                    Trace2.WriteLine("[V]PricingTemplate tab_DataBinding BEG.",DataTypeTraceSwitch.Sw.Info);
                Table target            = (Table)sender;
                TableRow rw             = target.Rows[0];

                RadComboBoxItem item    = (RadComboBoxItem)target.BindingContainer;
                Label target1           = (Label)rw.Cells[0].Controls[0];
                target1.Text            = DataBinder.Eval(item.DataItem, CrmStr.name).ToString();
                target1                 = (Label)rw.Cells[1].Controls[0];
                target1.Text            = DataBinder.Eval(item.DataItem, CrmStr.begindate).ToString();
                target1                 = (Label)rw.Cells[2].Controls[0];
                target1.Text            = DataBinder.Eval(item.DataItem, CrmStr.enddate).ToString();
                target1                 = (Label)rw.Cells[3].Controls[0];
                target1.Text            = DataBinder.Eval(item.DataItem, CrmStr.description).ToString();
                if ( DataTypeTraceSwitch.Sw.TraceVerbose )
                    Trace2.WriteLine("[V]PricingTemplate tab_DataBinding END.",DataTypeTraceSwitch.Sw.Info);
            }
        }

        #region Std Overrides

        protected override void OnInit(EventArgs e)
        {
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser OnInit BEG.",WebControlsTraceSwitch.Sw.Info);
            InitializeComponent();
            base.OnInit(e);
            if ( WebControlsTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CurrencyPricingChooser OnInit END.",WebControlsTraceSwitch.Sw.Info);
        }
        
        private void InitializeComponent()
        {
            Load                                +=  new EventHandler(Page_Load);
        }

        #endregion Std Overrides
    
    }
}
